<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <link rel="stylesheet" href="style.css">
    <title>Document</title>
    
</head>
<body>
    <div class="book p3d ">
        <!-- 右边 -->
<div class="book-cover"></div>
<!-- 左边 -->
<div class="front-cover p3d">
    <div class="page front flip p3d">
        <p>
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
            trgtrgrtvvrb trgtrgrtvvrb
       
        </p>
    </div>
    <div class="page back">

    </div>
</div>
    </div>
    <script>
        (function(){ //自行调用函数
var page=document.querySelector('.front-cover'),
hold=false,
centerPoint=window.innerWidth/2,//获取屏幕宽度
clamp=function(val,min,max){
return Math.max(min,Math.min(val,max))
}
   //console.log(page);
   //鼠标摁住时
   window.onmousedown=function(){
      // console.log('onmousedown');
       hold=true;
   }
   //鼠标放开时
   window.onmouseup=function(){
      // console.log('onmouseup');
       hold=false;
   }
   //翻书
window.onmousemove=function(evt){
   // console.log(evt);
    if(!hold){
return 
    }
    //计算一个合理的旋转角度
    var angle=clamp((centerPoint-evt.pageX+300)/300*-90,-180,0)
page.style.transform=`rotateY(${angle}deg)`
}

        })(window,document)
    </script>
</body>
</html>